import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'
//导入全局样式表
import './assets/admin/css/global.css'
//导入axios
import axios from 'axios'
// import qs from 'qs'
//导入过滤器
// import { nameSub,orderStateFilter } from './filters'
import * as filters from './filters'
//使用mixin混入全局变量和方法
import './utils/common.js'

//axios全局配置
// 默认请求的基础url（如果axios请求的地址不带域名，自动添加baseURL）（默认请求域名 + 当前域名）
axios.defaults.baseURL = 'http://localhost:8081/flower-store';

//请求拦截器
// axios.interceptors.request.use((req) => {
  //为请求头对象，添加token令牌
  // req.headers.token = window.sessionStorage.getItem("token");
  //拦截并stringify所有post参数
  // if(req.method === 'post'){
  //   req.data = qs.stringify(req.data);
  // }
//   return req;
// }, (error) => Promise.reject(error))

Vue.prototype.$target = "http://localhost:8081/flower-store/"; // 本地后端地址
//全局注册，使用方法为:this.$axios
Vue.prototype.$axios = axios

Vue.config.productionTip = false

//过滤时间
Vue.filter('dateFormat', function(originVal) {
  const dt = new Date(originVal);
  const y = dt.getFullYear();
  const m = (dt.getMonth + 1 + '').padStart(2, '0')
  const d = (dt.getDate + '').padStart(2, '0')

  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')
  
  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})
//过滤静态资源访问的路径
// Vue.filter('staticResources', function(originVal) {
//   if(originVal === '') return '';
//   const url = axios.defaults.baseURL + '/static';
//   return url + originVal;
// })

//全局注册过滤器
// Vue.filter('nameSub', nameSub);
// Vue.filter('orderStateFilter', orderStateFilter)
Object.keys(filters).forEach(key => {
    Vue.filter(key, filters[key])
})

//全局组件
import MyMenu from './components/MyMenu';
Vue.component(MyMenu.name, MyMenu);
import MyList from './components/MyList';
Vue.component(MyList.name, MyList);
import MyLogin from './components/MyLogin';
Vue.component(MyLogin.name, MyLogin);
import MyRegister from './components/MyRegister';
Vue.component(MyRegister.name, MyRegister);

new Vue({
  //挂载（注册）router实例
  router,
  store,
  render: h => h(App),
}).$mount('#app')
